<trkseg>
<trkpt lat="49.794688000" lon="9.834015000">
<ele>289.200000</ele>
- <time>2011-07-02T17:47:25Z</time>
+ <time>2011-07-02T17:47:25.2Z</time>
<speed>13.818100</speed>
<name>trkpt-2011-07-02T17:47:25.000Z</name>
<type>T</type>
</trkpt>
<trkpt lat="49.794710000" lon="9.833996000">
<ele>289.300000</ele>
- <time>2011-07-02T17:47:25Z</time>
+ <time>2011-07-02T17:47:25.4Z</time>
<speed>14.049800</speed>
<name>trkpt-2011-07-02T17:47:25.000Z</name>
<type>T</type>
</trkpt>
<trkpt lat="49.794734000" lon="9.833976000">
<ele>289.300000</ele>
- <time>2011-07-02T17:47:25Z</time>
+ <time>2011-07-02T17:47:25.6Z</time>
<speed>14.161100</speed>
<name>trkpt-2011-07-02T17:47:25.000Z</name>
<type>T</type>
</trkpt>
<trkpt lat="49.794758000" lon="9.833955000">
<ele>289.400000</ele>
- <time>2011-07-02T17:47:25Z</time>
+ <time>2011-07-02T17:47:25.8Z</time>
<speed>14.090400</speed>
<name>trkpt-2011-07-02T17:47:25.000Z</name>
<type>T</type>
</trkpt>
<trkpt lat="49.794782000" lon="9.833934000">
<ele>289.500000</ele>
- <time>2011-07-02T17:47:25Z</time>
+ <time>2011-07-02T17:47:26Z</time>
<speed>14.183800</speed>
<name>trkpt-2011-07-02T17:47:25.000Z</name>
<type>T</type>
<fix>3d</fix>
</trkpt>
-<!--
-<trkpt lat="49.794807000" lon="9.833916000">
- <ele>289.600000</ele>
- <time>2011-07-02T17:47:26Z</time>
- <speed>14.208100</speed>
- <name>trkpt-2011-07-02T17:47:26.000Z</name>
- <type>T</type>
- <fix>3d</fix>
-</trkpt>
-<trkpt lat="49.794831000" lon="9.833898000">
- <ele>289.800000</ele>
- <time>2011-07-02T17:47:26Z</time>
- <speed>14.272600</speed>
- <name>trkpt-2011-07-02T17:47:26.000Z</name>
- <type>T</type>
- <fix>3d</fix>
-</trkpt>
-<trkpt lat="49.794856000" lon="9.833881000">
- <ele>289.800000</ele>
- <time>2011-07-02T17:47:26Z</time>
- <speed>14.279100</speed>
- <name>trkpt-2011-07-02T17:47:26.000Z</name>
- <type>T</type>
- <fix>3d</fix>
-</trkpt>
-<trkpt lat="49.794880000" lon="9.833863000">
- <ele>289.800000</ele>
- <time>2011-07-02T17:47:26Z</time>
- <speed>14.085500</speed>
- <name>trkpt-2011-07-02T17:47:26.000Z</name>
- <type>T</type>
- <fix>3d</fix>
-</trkpt>
-<trkpt lat="49.794904000" lon="9.833847000">
- <ele>289.800000</ele>
- <time>2011-07-02T17:47:26Z</time>
- <speed>12.700900</speed>
- <name>trkpt-2011-07-02T17:47:26.000Z</name>
- <type>T</type>
- <fix>3d</fix>
-</trkpt>
--->
</trkseg>
</trk>
</gpx>
Write points to SubRip subtitle file (for video geotagging)
Copyright (C) 2010 Michael von Glasow, michael @t vonglasow d.t com
+ Copyright (C) 2014 Gleb Smirnoff, glebius @t FreeBSD d.t org
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
static char* opt_videotime;
static char* opt_gpstime;
static char* opt_gpsdate;
+static char* opt_format;
static time_t time_offset;
static int stnum;
static gbfile* fout;
return result;
}
-static time_t
-gps_to_video_time(time_t arg_gpstime)
+static QDateTime
+gps_to_video_time(QDateTime arg_gpstime)
{
- static time_t result;
+ QDateTime result = arg_gpstime;
/* Converts a GPS timestamp to relative time in the video stream. */
- result = arg_gpstime - time_offset;
+ result.addSecs(time_offset);
return result;
}
static void
-subrip_write_duration(time_t starttime, time_t endtime)
+subrip_write_duration(QTime starttime, QTime endtime)
{
/* Writes start and end time for subtitle display to file. */
- struct tm* tmptime;
-
- tmptime = gmtime(&starttime);
- gbfprintf(fout, "%02d:%02d:%02d,000 --> ", tmptime->tm_hour, tmptime->tm_min, tmptime->tm_sec);
-
- tmptime = gmtime(&endtime);
- gbfprintf(fout, "%02d:%02d:%02d,000\n", tmptime->tm_hour, tmptime->tm_min, tmptime->tm_sec);
-}
-
-static void
-subrip_write_time(time_t arg_time)
-{
- /* Writes a timestamp to file. */
- struct tm* tmptime;
+ gbfprintf(fout, "%02d:%02d:%02d,%03d --> ", starttime.hour(), starttime.minute(), starttime.second(), starttime.msec());
- tmptime = gmtime(&arg_time);
- gbfprintf(fout, "%02d:%02d:%02d", tmptime->tm_hour, tmptime->tm_min, tmptime->tm_sec);
+ gbfprintf(fout, "%02d:%02d:%02d,%03d --> ", endtime.hour(), endtime.minute(), endtime.second(), endtime.msec());
}
static void
/* Now that we have the next waypoint, we can write out the subtitle for
* the previous one.
*/
- time_t starttime;
- time_t endtime;
+ QDateTime starttime;
+ QDateTime endtime;
+ char *c;
- if (prevwpp->GetCreationTime().toTime_t() >= time_offset)
- /* if this condition is not true, the waypoint is before the beginning of
- * the video and will be ignored
- */
- {
+ /* If this condition is not true, the waypoint is before the beginning of
+ * the video and will be ignored
+ */
+ if (prevwpp->GetCreationTime().toTime_t() < time_offset)
+ return;
+ starttime = gps_to_video_time(prevwpp->GetCreationTime());
+ if (!waypointp) {
+ endtime = starttime.addSecs(1);
+ } else {
+ endtime = gps_to_video_time(waypointp->GetCreationTime());
+ }
+ gbfprintf(fout, "%d\n", stnum);
+ stnum++;
+ subrip_write_duration(starttime.time(), endtime.time());
+
+ for (c = opt_format; *c != '\0' ; c++) {
+ char fmt;
+
+ switch (*c) {
+ case '%':
+ fmt = *++c;
+ is_fatal(fmt == '\0', "No character after %% in subrip format");
+
+ switch (fmt) {
+ case 's':
+ if WAYPT_HAS(prevwpp, speed)
+ gbfprintf(fout, "%2.1f", MPS_TO_KPH(prevwpp->speed));
+ else
+ gbfprintf(fout, "--.-");
+ break;
+ case 'e':
+ if (prevwpp->altitude != unknown_alt)
+ gbfprintf(fout, "%4d", (int)prevwpp->altitude);
+ else
+ gbfprintf(fout, " -");
+ break;
+ case 't':
+ {
+ QTime t = prevwpp->GetCreationTime().time();
+ gbfprintf(fout, "%02d:%02d:%02d", t.hour(), t.minute(), t.second());
+ break;
+ }
+ case 'l':
+ // The +.00005 is for rounding.
+ gbfprintf(fout, "Lat=%0.5lf Lon=%0.5lf",
+ prevwpp->latitude+.000005, prevwpp->longitude+.000005);
+ break;
+ case 'c':
+ if (prevwpp->cadence != 0)
+ gbfprintf(fout, "%3u", prevwpp->cadence);
+ else
+ gbfprintf(fout, " -");
+ break;
+ case 'h':
+ if (prevwpp->heartrate != 0)
+ gbfprintf(fout, "%3u", prevwpp->heartrate);
+ else
+ gbfprintf(fout, " -");
+ break;
+ }
- starttime = gps_to_video_time(prevwpp->GetCreationTime().toTime_t());
- if (!waypointp) {
- endtime = starttime + 1;
- } else {
- endtime = gps_to_video_time(waypointp->GetCreationTime().toTime_t());
- }
- gbfprintf(fout, "%d\n", stnum);
- stnum++;
- subrip_write_duration(starttime, endtime);
- if WAYPT_HAS(prevwpp, speed) {
- gbfprintf(fout, "%d km/h",
- (int)(MPS_TO_KPH(prevwpp->speed) + 0.5));
- }
- if (prevwpp->altitude != unknown_alt) {
- if WAYPT_HAS(prevwpp, speed) {
- gbfprintf(fout, ", ");
+ break;
+
+ case '\\':
+ fmt = *++c;
+ is_fatal(fmt == '\0', "No character after \\ in subrip format");
+ switch (fmt) {
+ case 'n':
+ gbfprintf(fout, "\n");
+ break;
}
- gbfprintf(fout, "%d m\n",
- (int)(prevwpp->altitude + 0.5));
- } else if WAYPT_HAS(prevwpp, speed) {
- gbfprintf(fout, "\n");
+ break;
+ default:
+ gbfwrite(c, 1, 1, fout);
}
- subrip_write_time(prevwpp->GetCreationTime().toTime_t());
- gbfprintf(fout, " Lat=%0.5lf Lon=%0.5lf\n",
- prevwpp->latitude + .000005,
- prevwpp->longitude + .000005);
- gbfprintf(fout, "\n");
}
+ gbfprintf(fout, "\n\n");
}
/* callback functions */
{"video_time", &opt_videotime, "Video position for which exact GPS time is known (hhmmss, default is 0:00:00)", 0, ARGTYPE_STRING, ARG_NOMINMAX },
{"gps_time", &opt_gpstime, "GPS time at position video_time (hhmmss, default is first timestamp of track)", 0, ARGTYPE_STRING, ARG_NOMINMAX },
{"gps_date", &opt_gpsdate, "GPS date at position video_time (hhmmss, default is first timestamp of track)", 0, ARGTYPE_STRING, ARG_NOMINMAX },
+ {"format", &opt_format, "Format for subtitles", "%s km/h %e m\n%t %l", ARGTYPE_STRING, ARG_NOMINMAX },
ARG_TERMINATOR
};